package com.tj.tj_java.controller;

import com.tj.tj_java.dto.UserLoginDto;
import com.tj.tj_java.dto.UserCredentialsDto;
import com.tj.tj_java.result.Result;
import com.tj.tj_java.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//控制层
@Slf4j
@RestController
public class UserController {
    //注入service
    @Autowired
    private UserService userService;

    /*
    * 发送验证码接口
    * 接收路径参数 /email
    * */
    @GetMapping("/VerifyCode/")
    public Result SendVerificationCode(@RequestParam String email, @RequestParam String codeType){
        //log.info("邮箱名:{}",email);
        System.out.println("发送验证码接口->"+email+"验证码类型"+codeType);
        return userService.SendVerificationCode(email,codeType);
    }

    /*
    * 用户登录接口
    * 接收{name,password} 成功返回{userId,email,name}
    * */
    @PostMapping("/login")
    public Result login(@RequestBody UserLoginDto userLoginDto) {
        System.out.println("用户登录接口->"+userLoginDto);
        return userService.login(userLoginDto);
    }

    /*
    * 用户注册接口
    * 接收 {name,password,email,verifyCode}
    * */
    @PostMapping("/register")
    public Result register(@RequestBody UserCredentialsDto userCredentialsDto){
        System.out.println("用户注册接口->"+ userCredentialsDto);
        return userService.register(userCredentialsDto);
    }

    /*
    * 修改用户密码接口
    * 接收 {name,password,email,verifyCode}
    * */
    @PostMapping("/updatePassword")
    public Result alterPassword(@RequestBody UserCredentialsDto userCredentialsDto){
        System.out.println("修改密码_控制层收到"+ userCredentialsDto);
        return userService.updatePassword(userCredentialsDto);
    }
//----------------------------------------------------------

}
